﻿using System;

namespace Glue.Internals.Nulls
{
    /// <summary>
    /// Maybe means I can not guarantee that I've got the object you're asking for. When you receive a maybe, check if it contains a value.
    /// </summary>
    /// <typeparam name="T">The type of the object you _might_ get</typeparam>
    internal class Maybe<T>
    {
        private readonly T value;

        public static Maybe<T> Nothing() {return new Maybe<T>(default(T));}

        public Maybe(T value)
        {
            this.value = value;
        }

        public bool HasValue()
        {
            return value != null;
        }

        public T GetValue()
        {
            if (!HasValue()) throw new ArgumentException("This Maybe has no value!");

            return value;
        }
    }

    internal class Maybe: Maybe<object>
    {
        public new static Maybe Nothing() { return new Maybe(null); }

        public Maybe(object value) : base(value) {}
    }

}
